import {ref, reactive,} from 'vue'
import {myOverList, myOverListCount} from '@/utlis/interface/Wode'

export default (Proxy: any) => {
    // 位置组件配置
    // tabs样式
    const inactiveStyle = reactive({
        color: '#000',
        transform: 'scale(1)',

    })
    const activeStyle = reactive({
        color: '#000',
        fontWeight: 'bold',
        transform: 'scale(1.1)',
    })
    // tabs数组
    const list = reactive([
        {
            name: `外卖`,
            key: 0,
            value: null
        },
        {
            name: `跑腿`,
            key: 1,
            value: null
        },
    ])
    const baseData = reactive({
        pageNo: 1,
        pageSize: 10,
        distributionType: 0,  //配送类型 0:外卖 1:跑腿

    })
    //  我的订单数量
    const OverListCount = () => {
        myOverListCount('', Proxy).then((res: any) => {
            if (res.code == 0) {
                list[0].name = `外卖(${res.data.takeOutCompletedNumber > 99 ? '99+' : res.data.takeOutCompletedNumber})`
                list[1].name = `跑腿(${res.data.runCompletedNumber > 99 ? '99+' : res.data.runCompletedNumber})`
            }
        }).catch((err: any) => {

            console.log(err);

        })

    }

    const listItem = reactive<any>({
        list: [],
        list_show: true
    })
    //我的已完成订单
    const Overllist = () => {
        // if (baseData.distributionType == 1) return listItem.list = []
        myOverList(baseData, Proxy).then((res: any) => {
            if (res.code == 0 && res.data != null) {
                res.data?.forEach((item: any, index: number) => {
                    let obj = {
                        id: item.orderId,
                        deliveryTime: item.deliveryTime,
                        expireTime: item.expireTime,
                        predictTime: item.predictTime,
                        goodsName: item.goodsName,
                        goodsNum: item.goodsNum,
                        locationVO: item.locationVO,
                        mobile: item.mobile,
                        name: item.name,
                        orderNo: item.orderNo,
                        pickAddress: item.pickAddress,
                        pickGoodsTime: item.pickGoodsTime,
                        pickName: item.pickName,
                        pickPhone: item.pickPhone,
                        placeOrderTime: item.placeOrderTime,
                        price: item.price,
                        receiveAddress: item.receiveAddress,
                        remark: item.remark,
                        riderClientStatus: item.riderClientStatus,
                        shortName: item.shortName,
                        startingLatitude: item.startingLatitude,
                        startingLongitude: item.startingLongitude,
                        terminalLatitude: item.terminalLatitude,
                        terminalLongitude: item.terminalLongitude,
                        merchantClientStatus: item.merchantClientStatus,
                        orderSn: item.orderSn,
                        result: item.result,
                        dayNum: item.dayNum,
                        startTime: item.startTime,
                        distance: item.distance,
                        merchantName: item.merchantName,
                        riderToMerchantDistance: item.riderToMerchantDistance == null ? '0' : item.riderToMerchantDistance,
                        sfBuy: 0,
                        riderDo: item.riderDo,
                        overListShow: baseData.distributionType == 0
                    }
                    listItem.list.push(obj)
                })
            } else {
                listItem.list_show = false

            }
        })
    }
    // tabs分类默认值
    const Type = ref(0)
    // tabs切换
    const Tabs = (item: any) => {
        baseData.distributionType = list[item.index].key
        listItem.list = []
        baseData.pageNo = 1
        Overllist()
    }
    return {inactiveStyle, activeStyle, Tabs, list, Type, Overllist, listItem, baseData, OverListCount}
}
